package com.kyzh.core.utils

import android.app.Activity
import android.content.Context
import android.util.Log
import com.duoyou.task.openapi.DyAdApi
import com.gushenge.core.aesEcbDecode
import com.kyzh.core.activities.*

import com.gushenge.core.beans.Nav
import com.gushenge.core.dao.GlobalKeys
import com.gushenge.core.dao.MMKVConsts
import com.gushenge.core.toast
import com.kyzh.core.activities.BrowserActivity
import com.kyzh.core.pager.home.MainActivity
import com.kyzh.core.activities.MyGiftActivity
import com.kyzh.core.pager.weal.accountbuy.DealActivity
import com.kyzh.core.pager.weal.vip.OpenVipActivity
import com.kyzh.core.pager.me.settings.SettingsV3Activity
import com.kyzh.core.pager.weal.coupon.CouponActivity
import com.kyzh.core.pager.weal.sign.SignActivity
import com.kyzh.core.pager.weal.vip.VipActivity
import com.kyzh.core.pager.weal.vip.VipCentreActivity
import com.kyzh.core.pager.weal.cloud.CloudGameActivity
import com.kyzh.core.pager.weal.community.CommunityListActivity
import com.kyzh.core.activities.weal.gift.GiftActivity
import com.kyzh.core.pager.weal.community.CommunityActivity
import com.kyzh.core.pager.weal.groupchat.GroupChatActivity
import com.kyzh.core.pager.me.about.AboutActivity
import com.kyzh.core.pager.me.user.SafetyActivity
import com.kyzh.core.pager.weal.accountbuy.SmallAccountManagerActivity
import com.kyzh.core.pager.weal.rank.RankActivity
import com.kyzh.core.pager.weal.recover.RecoverActivity
import com.kyzh.core.pager.weal.serverlist.ServerActivity
import com.kyzh.core.pager.weal.share.ShareNewActivity

fun Context.navClickByLogin(item: Nav) {
    if (item.login == 1) {
        if (startLogin()) {
            NavClick(item)
        }
    } else {
        NavClick(item)
    }
}


fun Context.NavClick(item: Nav) {
    Log.e("TAG", "NavClick: " + item.name + item.type)
    if (item.url.isNotEmpty()) {
        when (item.type) {
            // 云游戏
            367 -> {
                CloudGameActivity.start(this)
            }
            // 会员
            316 -> VipActivity.start(this)
            346 -> {
                if (packageName == "a94hwan.bjkyzh.star") {
                    CommunityActivity.start(this as Activity, "")
                } else {
                    startActivity<CommunityListActivity>()
                }
//                startActivity<BrowserActivity>(GlobalKeys.TITLE to item.name, GlobalKeys.LINK to  item.url,"TYPE" to item.type)
            }

            else -> {
                startActivity<BrowserActivity>(GlobalKeys.TITLE to item.name, GlobalKeys.LINK to item.url)
            }
        }

    } else {
        when (item.type) {
            //群聊推荐
            370 -> {
                DyAdApi.getDyAdApi().jumpAdList(this, aesEcbDecode(MMKVConsts.uid), 0);

            }
            //// 小游戏
            369 -> {
            }

            368 -> {

                GroupChatActivity.start(this)

            }
            //社区列表
            346 -> {
                if (packageName == "a94hwan.bjkyzh.star") {
                    CommunityActivity.start(this as Activity, "")
                } else {
                    startActivity<CommunityListActivity>()
                }
            }
            // 云游戏
            367 -> {
                CloudGameActivity.start(this)
            }
            // 直播
            364 -> {
                if (this is MainActivity) {
                    this.quanzi(1)
                }
            }
            // 圈子
            365 -> {
                if (this is MainActivity) {
                    this.quanzi(0)
                }
            }

            366 -> {
                if (this is MainActivity) {
                    this.fuli()
                }
            }

            301 -> startActivity<MyGiftActivity>()
            302 -> startActivity<BillActivity>()
            303 -> startActivity<SmallAccountManagerActivity>()
            304 -> startActivity<CollectionActivity>()
            305 -> startActivity<TiedMoneyActivity>()
            306 -> startActivity<SettingsV3Activity>()
            /*307-> 客服中心 */
            308 -> startActivity<SafetyActivity>()
            /*309-> 申请返利*/
            310 -> startActivity<RankActivity>()
            311, 339 -> GiftActivity.start(this)
            312 -> startActivity<ServerActivity>()
            313 -> startActivity<ShareNewActivity>()
            314 -> startActivity<CouponActivity>()
            315 -> startActivity<MyAssets1Activity>()
            316 -> OpenVipActivity.start(this)
            317 -> startActivity<MyDiscussActivity>()
            318 -> startActivity<AboutActivity>()
            321 -> startActivity<SignActivity>()
            320 ->
                startActivity<BaseFragmentActivity>(
                    GlobalKeys.TYPE to BaseFragmentActivity.RENWUZHUANJIN,
                )

            //name=账号交易
            328 -> {
                if (startLogin()) {
                    startActivity<DealActivity>()
                }
            }
            //name=积分商城
            329 -> {
                if (startLogin()) {
                    startActivity<PointsMallActivity>()
                }
            }
            //name=每日答题
            331 -> if (startLogin()) {
                AnswerActivity.start(this)
            }
//                name=小号回收
            332 -> if (startLogin()) {
                RecoverActivity.start(this)
            }
//                    name=积分任务

            333 -> if (startLogin()) {


                startActivity<TaskCenterActivity>()
            }

            334 -> if (startLogin()) {
                startActivity<VipCentreActivity>()
            }

            335 -> if (startLogin()) {
                startActivity<MyCollectActivity>()
            }

            337 -> {
                if (startLogin()) {
                    startActivity<BaseFragmentActivity>(GlobalKeys.TYPE to BaseFragmentActivity.MONEYCARD)
                }
            }

            888 -> if (startLogin()) {
                startActivity<BackgroundActivity>()
            }

            else -> {
                "敬请期待".toast()
            }
        }
    }
}